package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Project;
import cn.wolfcode.crm.domain.FailLog;
import cn.wolfcode.crm.domain.Transfer;
import cn.wolfcode.crm.query.ProjectQueryObject;
import cn.wolfcode.crm.service.IProjectService;
import cn.wolfcode.crm.service.IFailLogService;
import cn.wolfcode.crm.service.ITransferService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PageResult;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("project")
public class ProjectController {

    @Autowired
    private IProjectService projectService;

    @RequestMapping("potential")
    @RequiresPermissions(value = {"project:potential","潜在客户计划页面"},logical = Logical.OR)
    public String potential(){
        return "project/potential";
    }
    @RequestMapping("formal")
    @RequiresPermissions(value = {"project:formal","正是客户跟进计划页面"},logical = Logical.OR)
    public String formal(){
        return "project/formal";
    }

    @RequestMapping("selectAll")
    @ResponseBody
    public List<Project> selectAll(){
        return projectService.selectAll();
    }

    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public JsonResult saveOrUpdate(Project entity) {
        JsonResult jsonResult = new JsonResult();
        try{
            projectService.saveOrUpdate(entity);
        }catch (Exception e){
            jsonResult.mark("操作失败");
        }
        return jsonResult;
    }

    @RequestMapping("delete")
    @ResponseBody
    public JsonResult delete(Long id) {
        JsonResult jsonResult = new JsonResult();
        try{
            projectService.deleteByPrimaryKey(id);
        }catch (Exception e){
            jsonResult.mark("操作失败");
        }
        return jsonResult;
    }

    @RequestMapping("list")
    @ResponseBody
    public PageResult list(ProjectQueryObject qo) throws Exception{
        return projectService.query(qo);
    }
    //标记结果
    @RequestMapping("report")
    @ResponseBody
    public JsonResult report(Project entity) throws Exception{
        JsonResult jsonResult = new JsonResult();
        try{
            projectService.changeReport(entity);
        }catch (Exception e){
            jsonResult.mark("操作失败");
        }
        return jsonResult;
    }



}
